package com.css.Thread;


import java.util.concurrent.locks.ReentrantLock;

public class TestLock {
    public static void main(String[] args) {
        Lock lock=new Lock();
        new Thread(lock,"css").start();
        new Thread(lock,"dd").start();
    }

}
class Lock implements Runnable{
    int tickNum=10;
    private final ReentrantLock lock=new ReentrantLock();
    @Override
    public void run() {
        while (true){
            try {
                lock.lock();
                if(tickNum<=0){
                    break;
                }
                System.out.println(Thread.currentThread().getName()+"->"+tickNum--);
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }

            }finally {
                lock.unlock();

            }

        }

    }
}
